package com.dzqc.fly.controller.mobile;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dzqc.fly.common.Kv;
import com.dzqc.fly.common.Result;
import com.dzqc.fly.db.form.SecretaryForm;
import com.dzqc.fly.db.pojo.SecretaryStudentsPojo;
import com.dzqc.fly.db.vo.SecretaryStudentDetailVo;
import com.dzqc.fly.db.vo.SecretaryStudentsTimeVo;
import com.dzqc.fly.db.vo.SecretarySumVo;
import com.dzqc.fly.service.SecretaryStudentsService;
import com.dzqc.fly.service.SecretarySumService;
import com.dzqc.fly.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;


/**
 * @author Administrator
 */
@RestController
@RequestMapping("/secretary/sum")
@Tag(name = "SecretarySumController", description = "手机端用户Web接口")
@Slf4j
@EnableAutoConfiguration
public class SecretarySumController {

    @Autowired
    private UserService userService;
    @Autowired
    private SecretarySumService secretarySumService;

    @Autowired
    private SecretaryStudentsService secretaryStudentsService;


    @GetMapping("/searchColleges")
    @Operation(summary = "书记辖内院系信息")
    public Result searchColleges(SecretaryForm secretaryForm){
        HashMap userinfoMap =userService.searchUserInfo(StpUtil.getLoginIdAsInt());
        HashMap param= new HashMap(){
            {
                put("sno", userinfoMap.get("sno"));//书记工号
                put("classId",secretaryForm.getClassId());//班级id
            }
        };
        SecretarySumVo result=secretarySumService.searchColleges(param);

        return Result.commonOk(result);
    }


    @RequestMapping(value="/searchStudentsByTime" ,method = RequestMethod.GET)
    @Operation(summary = "书记辖内院系按照日期排序的学生列表信息")
    @SaCheckLogin
    public Result searchStudentsByTime(SecretaryForm secretaryForm){
        HashMap userinfoMap =userService.searchUserInfo(StpUtil.getLoginIdAsInt());
        HashMap param= new HashMap(){
            {
                put("sno", userinfoMap.get("sno"));//书记工号
                put("classId",secretaryForm.getClassId());//班级id
            }
        };
        SecretaryStudentsTimeVo result=secretarySumService.searchStudentsByTime(param);

        return Result.commonOk(result);
    }

    @RequestMapping(value="/searchStudentsList" ,method = RequestMethod.GET)
    @Operation(summary = "书记辖内班级学生列表")
    @SaCheckLogin
    public Result searchStudentList(SecretaryForm secretaryForm){
        HashMap userinfoMap =userService.searchUserInfo(StpUtil.getLoginIdAsInt());
        HashMap param= (HashMap) Kv.toKv(secretaryForm);
        param.put("sno",userinfoMap.get("sno"));
        Page<SecretaryStudentsPojo> result=secretaryStudentsService.searchStudentsList(param);
        return Result.commonOk(result);
    }
    @RequestMapping(value="/searchStudentsDetail" ,method = RequestMethod.GET)
    @Operation(summary = "书记辖内班级学生详情")
    @SaCheckLogin
    public Result searchStudentsDetail(SecretaryForm secretaryForm){
        HashMap userinfoMap =userService.searchUserInfo(StpUtil.getLoginIdAsInt());
        HashMap param= (HashMap) Kv.toKv(secretaryForm);
        param.put("sno",userinfoMap.get("sno"));
        SecretaryStudentDetailVo result=secretaryStudentsService.searchStudentsDetail(param);

        return Result.commonOk(result);
    }
}
